package city.spring.modules.work.entity;

import city.spring.configure.mybatis.FillCurrentUser;
import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * 实体类：排班方案（上班方案）
 *
 * @author 侯坤林
 * @date 2020-06-04 16:43:43
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("work_plan")
public class WorkPlanEntity implements Serializable {

    /**
     * 主键ID
     */
    @TableId(type = IdType.ASSIGN_ID)
    private String id;

    /**
     * 排班方案所属组织机构
     */
    @FillCurrentUser(FillCurrentUser.Type.OrgId)
    @TableField(fill = FieldFill.INSERT, updateStrategy = FieldStrategy.NEVER)
    private String orgId;

    /**
     * 排班方案名称
     */
    private String title;

    /**
     * 工作日（周一到周日）
     */
    private String workingDay;

    /**
     * 更新次数（乐观锁）
     */
    @Version
    private Integer version;

    /**
     * 数据创建时间
     */
    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private Date gmtCreated;

    /**
     * 数据更新时间
     */
    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private Date gmtModified;

    public Set<String> getWorkingDaySet() {
        return StringUtils.commaDelimitedListToSet(workingDay);
    }

    public void setWorkingDaySet(List<String> list) {
        this.workingDay = String.join(",", list);
    }

    public void setWorkingDay(String workingDay) {
        this.workingDay = workingDay;
    }

    public void setWorkingDay(List<String> list) {
        this.workingDay = String.join(",", list);
    }
}